#!/bin/bash
rpm_mysql=`rpm -qa|grep mysql|wc -l`
Mysql_init=`ss -lntp|grep 3306|grep -v grep|wc -l`
Mysql_passwd=`grep "temporary password" /var/log/mysqld.log|awk -F "[ :]+" '{print $NF}'`
if [ $rpm_mysql -eq 0 ];then
	echo "Mysql is not install..."
	[ -d /home/packages ] || mkdir -p /home/packages
	cd /home/packages && wget -q http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
    rpm -ivh /home/packages/mysql57-community-release-el7-8.noarch.rpm
    yum clean all && yum makecache
    yum install mysql-community-server -y
    if [ $Mysql_init -eq 0 ];then
    	systemctl start mysqld
    	systemctl status mysqld &>/dev/null
    	if [ $? -eq 0 ];then
    		echo "Mysqld is running..."
    		systemctl enable mysqld
    		mysqladmin -uroot "-p$Mysql_passwd" password "Xujun66207383!@#$"
            exit 0
    	else
    		echo "Mysqld is no running"
    		exit 1
    	fi

    fi
else
	echo "Mysql is install..."
	exit 0
fi